<template>
  <div>
    <el-card>
      <el-form ref="createOrderFormRef" :model="CreateForm" label-width="100px">
        <el-form-item label="产品名称">
          <el-input v-model="CreateForm.productName"></el-input>
        </el-form-item>
        <el-form-item label="产品序列号">
          <el-input v-model="CreateForm.productSN"></el-input>
        </el-form-item>
        <el-form-item label="客户名称">
          <el-input v-model="CreateForm.clientName"></el-input>
        </el-form-item>
        <el-form-item label="客户电话">
          <el-input v-model="CreateForm.clientPhone"></el-input>
        </el-form-item>
        <el-form-item label="客户地址">
          <el-input v-model="CreateForm.clientAddress"></el-input>
        </el-form-item>
        <el-form-item label="故障描述">
          <el-input v-model="CreateForm.clientDesc"></el-input>
        </el-form-item>
        <el-form-item label="发票">
          <el-input v-model="CreateForm.invoice"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="onSubmit">立即创建</el-button>
          <el-button @click="cancelClick">取消</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script setup>
import workOrderApi from "/src/api/order"
import { onMounted, reactive, ref } from "vue";
import { ElMessage, ElMessageBox } from 'element-plus';
import { useRouter } from 'vue-router'
import { useUserStore } from "/src/store/user";
import { useOrdersStore } from "/src/store/order"
import EngineerApi from "../../api/engineer.js";

const userStore = useUserStore();
const orderStore = useOrdersStore();
const router = useRouter();
// Dom 挂载之后
onMounted(() => {
})

const createOrderFormRef = ref()
const CreateForm = reactive({
  productName:'aa',
  productSN:'bb',
  clientId:'cc',
  clientName:'dd',
  clientPhone:'ee',
  clientAddress:'ff',
  clientDesc:'gg',
  invoice:'hh'
})


// 创建工单
const onSubmit = async () => {
  // 获取下单用户的Id
  CreateForm.clientId = userStore.state.user.id
  console.log(CreateForm)
  // const res = await workOrderApi.createWorkOrder(form);
  const res = await workOrderApi.createWorkOrder(CreateForm);
  console.log(res)
  if (res.data) {
    if (res.data.code === 200) {
      ElMessage.success("工单创建成功");
      router.push("/order/list");
    } else {
      ElMessage.error(res.data.data);
    }
  } else {
    ElMessage.error("服务器内部错误");
  }
}

//取消创建
const cancelClick = () => {
  router.push("/order/list");
}

</script>

<style scoped>
.image-slot {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    background: var(--el-fill-color-light);
    color: var(--el-text-color-secondary);
    font-size: 30px;
}

.image-slot .el-icon {
    font-size: 30px;
}
</style>